package com.yixiang.np.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	/**
	 * 格式化字符串
	 * 
	 * 例：formateString("xxx{0}bbb",1) = xxx1bbb
	 * 
	 * @param str
	 * @param params
	 * @return
	 */
	public static String formateString(String str, String... params) {
		for (int i = 0; i < params.length; i++) {
			str = str.replace("{" + i + "}", params[i] == null ? "" : params[i]);
		}
		return str;
	}

	public static boolean isNull(Object obj){
		if(obj == null){
			return true;
		}else if("".equals(obj)){
			return true;
		}else{
			return false;
		}
	}
	
	public static String formaterNull(String obj,String param){
		if(obj == null){
			return param;
		}else if("".equals(obj)){
			return param;
		}else{
			return obj;
		}
	}
	//判断是否是中文
	public static boolean isChineseChar(String str) {
		boolean temp = false;
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher m = p.matcher(str);
		if (m.find()) {
			temp = true;
		}
		return temp;
	}
}
